#!/usr/bin/perl
# download_log.cgi

use File::Basename;
require './mdmhistory-lib.pl';
&ReadParse();
&header($text{'download_log'},"", "download", 1, 1);

my $filename=$config{mdmlogfile};
my $dir=dirname($filename);
my $base=basename($filename);

opendir(DIR,"$dir");
my @list=grep(/^$base/,readdir(DIR));
closedir(DIR);

print <<EOF;
<table class=mode1 border=0 width=100% align=center cellspacing=0 cellpadding=0>
<tr class=title1>
<td><b>$text{'log_name'}</b></td>
<td><b>$text{'log_size'}</b></td>
<td><b>$text{'log_backuptime'}</b></td>
</tr>
EOF

foreach $filename (@list) {
	my (@st,$ctime,$downfile);

	@st=stat("$dir/$filename");
	next unless( $st[7] >0 );

	if( $filename !~ /\.gz/){ 
		$downfile="$filename.log";
		$type='text';
	}else{
		$downfile="$filename";
		$ctime=scalar localtime($st[10]);
		$type='binary';
	}
	
	unlink($downfile) if(-e $downfile);
	symlink("$dir/$filename",$downfile);
	$mode=$mode eq 'mode1' ? 'mode2':'mode1';

print <<EOF;
<tr class=$mode>
<td>
    <a href=$downfile><img border=0 src=../images/$type.gif></a>&nbsp;$downfile 
</td>
<td>$st[7]</td>
<td>$ctime</td>
</tr>
EOF

}
print "</table>";
&footer("index.cgi", $text{'index_title'});
